package cn.itcast.scm.action;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.itcast.scm.entity.Goods;
import cn.itcast.scm.entity.Page;
import cn.itcast.scm.service.GoodsService;

@Controller
@RequestMapping("/goods")
public class GoodsAction extends BaseAction{
	@Resource
	private GoodsService goodsService;
	
	@RequestMapping(value="/insert")
	@ResponseBody //如果返回json格式，需要这个注解，这里用来测试环境
	public Object insert(Goods goods){
		System.out.println("---action.goods:"+goods);
		int i = 0;
		try {
			i = goodsService.insert(goods);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return i;
	}
	
	@RequestMapping("/deleteList")
	@ResponseBody // 如果返回json格式，需要这个注解，这里用来测试环境
	public Object deleteList(String[] pks) {
		System.out.println("---doAjax.deleteList:" + pks);
		int i = 0;
		try {
			i = goodsService.deleteList(pks);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return i;
	}
	
	@RequestMapping(value="/update")
	@ResponseBody //如果返回json格式，需要这个注解，这里用来测试环境
	public Object update(Goods goods){
		System.out.println("---action.update.goods:"+goods);
		int i = 0;
		try {
			i = goodsService.update(goods);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return i;
	}
	
	// 通过关键字分页查询
		@RequestMapping("/selectPage")
		@ResponseBody // 如果返回json格式，需要这个注解，这里用来测试环境
		public Object selectPage(Page<Goods> page) {
			Page p = goodsService.selectPage(page);
			System.out.println("----page:" + page);

			return page.getPageMap();
		}

		// 通过关键字分页查询
		@RequestMapping("/selectPageUseDyc")
		@ResponseBody // 如果返回json格式，需要这个注解，这里用来测试环境
		public Object selectPageUseDyc(Page<Goods> page, Goods goods) {
			page.setParamEntity(goods);
			System.out.println("----page:" + page);

			Page p = goodsService.selectPageUseDyc(page);
			return p.getPageMap();
		}

		@RequestMapping("/doAjax")
		@ResponseBody // 如果返回json格式，需要这个注解，这里用来测试环境
		public Object doAjax(Goods goods) {
			System.out.println("---doAjax.goods:" + goods);
			goods.setGoodsName("goodsName1");
			return goods;
		}

}
